import axios from 'axios'
import qs from 'qs'
// const baseURL = 'http://192.168.2.199:12315'
// const baseURL = ' http://3915b2ec.cpolar.io' //外网访问地址
// axios.defaults.baseURL = baseURL

var instance = axios.create({ headers: 
    {'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'}  
  });

//请求拦截器,给所有的请求加上token
axios.interceptors.request.use(function (config) {
    //取出localStoasge中存储的token值
    let token = localStorage.getItem('mytoken')
    //设置请求头中Authorization这个名字是后台规定的
    config.headers['Authorization'] = token
    return config
}, function (error) {
    return Promise.reject(error)
})

//登录验证
export const login = (params) => {
   /*  return axios({
        method: 'post',
        url:'/Account/Login',
        data:params,
        transformRequest: [function (data) {
            // Do whatever you want to transform the data
            let ret = ''
            for (let it in data) {
              ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
            }
            return ret
          }],
    }) */
    return instance.post('/Account/Login',qs.stringify(params))
}

//注册验证
export const register = (params) => {
  return instance.post('/Account/Register',qs.stringify(params))
}
